import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Edge()
driver.get("https://www.jd.com/")
driver.find_element(By.CSS_SELECTOR, "#key").send_keys("电脑笔记本")
driver.find_element(By.CSS_SELECTOR, "#search > div > div.form > button > i").click()
time.sleep(5)
num = 1

for i in range(5):
    mylist = driver.find_elements(By.CSS_SELECTOR, "li")
    for li in mylist:
        try:
            llist = [
                "电脑名字：" + li.find_element(By.CSS_SELECTOR, ".p-name em").text.replace("\n", " "),
                "电脑简介：" + li.find_element(By.CSS_SELECTOR, ".p-name a").get_attribute("title").replace("\n", " "),
                "电脑价格：" + li.find_element(By.CSS_SELECTOR, ".p-price strong").text,
                "电脑评价：" + li.find_element(By.CSS_SELECTOR, ".p-commit strong").text,
                "电脑商铺：" + li.find_element(By.CSS_SELECTOR, ".J_im_icon a").text,
                "电脑状态：" + li.find_element(By.CSS_SELECTOR, ".p-icons").text.replace("\n", "，")
            ]
            print(f"第{num}台电脑\n"+"\n".join(llist))
            print("\n")
            num += 1
        except:
            pass
    driver.find_element(By.CSS_SELECTOR, "#J_bottomPage > span.p-num > a.pn-next > i").click()
    time.sleep(5)
